using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Decav.Gatsb.Data;

namespace Decav.Gatsb.Application.CommandWorkflow
{
	public partial class CreateNewTempLocationActivity: Activity
	{
		public CreateNewTempLocationActivity()
		{
			InitializeComponent();
		}

        /// <summary>
        /// The dependency property that gets or sets the name of the new location.
        /// </summary>
        public static DependencyProperty LocationNameProperty = DependencyProperty.Register(
            "LocationName", typeof(string), typeof(CreateNewTempLocationActivity));

        /// <summary>
        /// Gets or sets the name of the new location.
        /// </summary>
        public string LocationName
        {
            get { return (string)GetValue(LocationNameProperty); }
            set { SetValue(LocationNameProperty, value); }
        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            Location location = new Location(LocationName, LocationType.Unknown,
                GatsbApplication.Current.CurrentLocale, true);

            using (IGatsbDataAdapter adapt = GatsbApplication.Current.GetDataAdapter())
                adapt.CreateLocation(location);

            Location = location;

            return base.Execute(executionContext);
        }

        /// <summary>
        /// The dependency property that gets or sets the location that was created..
        /// </summary>
        public static DependencyProperty LocationProperty = DependencyProperty.Register(
            "Location", typeof(Location), typeof(CreateNewTempLocationActivity));

        /// <summary>
        /// Gets or sets the location that was created..
        /// </summary>
        public Location Location
        {
            get { return (Location)GetValue(LocationProperty); }
            set { SetValue(LocationProperty, value); }
        }
        
        
	}
}
